package web.beans;

import Car.bo.CarBo;
import Car.model.Car;
import Car.model.Transport;
import Car.model.spr.*;
import util.Context;

import javax.annotation.PostConstruct;
import javax.faces.event.ValueChangeEvent;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * Created by Новак on 30.11.2014.
 */

public class AddCarBean implements Serializable {
    List<spr_Color> colors;
    List<spr_Currency> currency;
    List<spr_TransportType> transportTypes;
    List<spr_Condition> conditions;
    List<spr_Brand> brands;
    List<spr_CarType> carTypes;
    List<spr_Model> models;
    List<spr_Privod> privods;
    List<spr_Transmission> transmissions;

    private int colorUser;
    private int currencyUser;
    private int transportTypesUser;
    private int conditionsUser;
    private int brandsUser;
    private int modelUser;
    private int carTypesUser;
    private int privodsUser;
    private int transmissionUser;
    private double price;
    private double capasity;
    private String description;


    CarBo carBo;

    @PostConstruct
    public void init() {
       carBo = (CarBo) Context.getAppContext().getBean("carBo");
        colors = carBo.getColor();
        currency = carBo.getCurrency();
        transportTypes = carBo.getTransportType();
        conditions = carBo.getCondition();
        brands = carBo.getBrand();
        carTypes = carBo.getCarType();
        models = carBo.getModel();
        privods = carBo.getPrivod();
        transmissions = carBo.getTransmission();

    }


    public String addCar() {
        //Добавление
//        Transport tr = new Transport(brands.get(0),222,new Date(),currency.get(0),conditions.get(0),colors.get(0),transportTypes.get(0),"111!!!!!!!");
//        carBo.addCar(new Car(carTypes.get(1),models.get(1),privods.get(1),transmissions.get(0),tr,2),tr);

        //После успешного добавления перейти на страницу со своим объявление
       Transport transport=new Transport(brands.get(brandsUser-1),price,new Date(),currency.get(currencyUser-1),conditions.get(currencyUser-1),colors.get(colorUser-1),transportTypes.get(transportTypesUser-1),description);
        carBo.addCar(new Car(carTypes.get(carTypesUser-1),models.get(modelUser-1),privods.get(privodsUser-1),transmissions.get(transmissionUser-1),transport,capasity),transport );
       // carBo.addCar(new Car(carTypes.get(1),models.get(1),privods.get(1),transmissions.get(0),transport,2),transport);

       // Transport tr = new Transport(brands.get(0),222,new Date(),currency.get(0),conditions.get(0),colors.get(0),transportTypes.get(0),"111!!!!!!!");
       // carBo.addCar(new Car(carTypes.get(1),models.get(1),privods.get(1),transmissions.get(0),tr,2),tr);


        return null;
    }

    //**********************
    public void colorSet(ValueChangeEvent e) {
        colorUser = new Integer(e.getNewValue().toString());
    }
    public void currencySer(ValueChangeEvent e) {
        currencyUser = new Integer(e.getNewValue().toString());
    }
    public void transportTypeSet(ValueChangeEvent e) {
        transportTypesUser = new Integer(e.getNewValue().toString());
    }
    public void conditionsSet(ValueChangeEvent e) {
        conditionsUser = new Integer(e.getNewValue().toString());
    }
    public void modelSet(ValueChangeEvent e) {
        modelUser = new Integer(e.getNewValue().toString());
    }

    public void brandSet(ValueChangeEvent e) {
        brandsUser = new Integer(e.getNewValue().toString());
    }
    public void carTypesSet(ValueChangeEvent e) {
        carTypesUser = new Integer(e.getNewValue().toString());
    }
    public void privodSet(ValueChangeEvent e) {
        privodsUser = new Integer(e.getNewValue().toString());
    }
    public void transmissionSet(ValueChangeEvent e) {
        transmissionUser = new Integer(e.getNewValue().toString());
    }

    //*************
    public List<spr_Color> getColors() {
        return colors;
    }

    public void setColors(List<spr_Color> colors) {
        this.colors = colors;
    }

    public List<spr_Currency> getCurrency() {
        return currency;
    }

    public void setCurrency(List<spr_Currency> currency) {
        this.currency = currency;
    }

    public List<spr_TransportType> getTransportTypes() {
        return transportTypes;
    }

    public void setTransportTypes(List<spr_TransportType> transportTypes) {
        this.transportTypes = transportTypes;
    }

    public List<spr_Condition> getConditions() {
        return conditions;
    }

    public void setConditions(List<spr_Condition> conditions) {
        this.conditions = conditions;
    }

    public List<spr_Brand> getBrands() {
        return brands;
    }

    public void setBrands(List<spr_Brand> brands) {
        this.brands = brands;
    }

    public List<spr_CarType> getCarTypes() {
        return carTypes;
    }

    public void setCarTypes(List<spr_CarType> carTypes) {
        this.carTypes = carTypes;
    }

    public List<spr_Model> getModels() {
        return models;
    }

    public void setModels(List<spr_Model> models) {
        this.models = models;
    }

    public List<spr_Privod> getPrivods() {
        return privods;
    }

    public void setPrivods(List<spr_Privod> privods) {
        this.privods = privods;
    }

    public List<spr_Transmission> getTransmissions() {
        return transmissions;
    }

    public void setTransmissions(List<spr_Transmission> transmissions) {
        this.transmissions = transmissions;
    }

    public int getBrandsUser() {
        return brandsUser;
    }

    public void setBrandsUser(int brandsUser) {
        this.brandsUser = brandsUser;
    }

    public int getModelUser() {
        return modelUser;
    }

    public void setModelUser(int modelUser) {
        this.modelUser = modelUser;
    }

    public int getColorUser() {
        return colorUser;
    }

    public void setColorUser(int colorUser) {
        this.colorUser = colorUser;
    }

    public int getCurrencyUser() {
        return currencyUser;
    }

    public void setCurrencyUser(int currencyUser) {
        this.currencyUser = currencyUser;
    }

    public int getTransportTypesUser() {
        return transportTypesUser;
    }

    public void setTransportTypesUser(int transportTypesUser) {
        this.transportTypesUser = transportTypesUser;
    }

    public int getConditionsUser() {
        return conditionsUser;
    }

    public void setConditionsUser(int conditionsUser) {
        this.conditionsUser = conditionsUser;
    }

    public int getCarTypesUser() {
        return carTypesUser;
    }

    public void setCarTypesUser(int carTypesUser) {
        this.carTypesUser = carTypesUser;
    }

    public int getPrivodsUser() {
        return privodsUser;
    }

    public void setPrivodsUser(int privodsUser) {
        this.privodsUser = privodsUser;
    }

    public int getTransmissionUser() {
        return transmissionUser;
    }

    public void setTransmissionUser(int transmissionUser) {
        this.transmissionUser = transmissionUser;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public double getCapasity() {
        return capasity;
    }

    public void setCapasity(double capasity) {
        this.capasity = capasity;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
}
